<template>
    <h2>添加门店信息</h2>

    <table border="1">
        <tr>
            <td>门店名称</td>
            <td>
                <input type="text" v-model="info.ShopName">
            </td>
        </tr>
        <tr>
            <td>分店名称</td>
            <td>
                <input type="text" v-model="info.Shop_BranchName">
            </td>
        </tr>
        <tr>
            <td>门店地址</td>
            <td>
             <textarea cols="20" rows="3" v-model="info.Shop_Address"></textarea>
            </td>
        </tr>
        <tr>
            <td>门店电话</td>
            <td>
                <input type="text" v-model="info.Shop_Phone">
            </td>
        </tr>
        <tr>
            <td>门店状态</td>
            <td>
                <input type="radio" v-model="info.Shop_State" :value="true"> 营业
                <input type="radio" v-model="info.Shop_State" :value="false">暂停营业
            </td>
        </tr>
        <tr>
            <td>门店介绍</td>
            <td>
                <textarea v-model="info.Shop_Info"></textarea>
            </td>
        </tr>
        <tr>
            <td>入住须知</td>
            <td>
                <textarea v-model="info.Shop_Notice"></textarea>
            </td>
        </tr>
        <tr>
            <td>交通信息</td>
            <td>
                <input type="text" v-model="info.Shop_Traffic">
            </td>
        </tr>
        <tr>
            <td>门店图片</td>
            <td>
                
                <input type="file" @change="UpLoad">
                <img style="width: 70px; height: 80px;" :src="info.Shop_Img"/>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="SaveData">
            </td>
        </tr>
        
        
        
    </table>

</template>
<script setup lang="ts">


import { onMounted,ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router=useRouter();



//文件上传
//文件上传
const UpLoad=(e:any)=>{

var file=e.target.files[0];
    var fd=new FormData();
    fd.append("img",file);

    axios.post('https://localhost:7153/api/Files/UpLoadFile',fd)
    .then(res=>{

        info.value.Shop_Img=res.data
    })
}

const info=ref({
    ShopName:"",
    Shop_BranchName:"",
    Shop_Address:"",
    Shop_Phone:"",
    Shop_State:true,
    Shop_Info:"",
    Shop_Notice:"",
    Shop_Traffic:"",
    Shop_Img:""


})

const SaveData=()=>{

    if(info.value.ShopName==""){
        alert("门店名称不能为空");
        return;
    }


    axios.post('https://localhost:7153/api/Shop/AddShop',info.value)
    .then(res=>{
        if(res.data==-1){
            alert("门店已经存在");
        }
        else if(res.data>0) 
        {
            alert("注册成功");
            router.push("/ShowShop");
        }
        else{
            alert("注册失败");
        }


    })


}



</script>